fix(avatar): snap size to backend sharp whitelist#3973
fix(avatar): snap size to backend sharp whitelist#3973PierreBrisorgueil merged 2 commits intomasterfrom
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 48 minutes and 26 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughUpdated the UserAvatarComponent to snap requested avatar sizes to backend-allowed values (128, 256, 512, 1024) instead of requesting arbitrary pixel sizes that trigger 422 errors. Added a computed property Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3973 +/- ##
=======================================
Coverage 99.48% 99.48%
=======================================
Files 30 30
Lines 968 968
Branches 267 267
=======================================
Hits 963 963
Misses 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes UserAvatarComponent image URL generation to request only backend-whitelisted sharp resize sizes, preventing HTTP 422 errors from /api/uploads/images/ across downstream consumers.
Changes:
- Added
avatarSizecomputed that snapssize * 2to the nearest allowed sharp size (capped at 1024). - Updated avatar image
setImages(...)call to useavatarSizeinstead ofsize * 2. - Added unit tests covering the size→whitelist mapping matrix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/modules/core/components/user.avatar.component.vue | Introduces sharp-size snapping via avatarSize and uses it in the image URL generation. |
| src/modules/core/tests/user.avatar.component.unit.tests.js | Adds unit tests validating the snapping behavior for several requested sizes. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/modules/core/tests/user.avatar.component.unit.tests.js`:
- Around line 89-115: Add an integration assertion that verifies the component's
render path calls setImages with the snapped avatar size: in the tests use
createWrapper(...) to mount the component for a representative size (e.g., size:
200), spy/mock the setImages function used by the component (via jest.spyOn or
by stubbing the imported helper), trigger a render/mount if necessary, then
assert that setImages was called and its avatarSize argument equals
wrapper.vm.avatarSize; ensure you restore the spy after the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 20f43747-a9e5-4328-8c08-2147eab1ea6d
📒 Files selected for processing (2)
src/modules/core/components/user.avatar.component.vuesrc/modules/core/tests/user.avatar.component.unit.tests.js
- add JSDoc header on avatarSize computed (Copilot review) - add integration test asserting setImages receives snapped size (CodeRabbit nitpick)
Closes #3972
Bug
UserAvatarComponentcallssetImages(config.api, user.avatar, size * 2, null), but the backend/api/uploads/images/endpoint only accepts the sharp-resize whitelist['128', '256', '512', '1024'](devkit Nodemodules/uploads/config/uploads.{env}.config.js). Any other value returns HTTP 422 "Wrong size param".Regression introduced by PR #3927 (Gravatar → UserAvatarComponent). Pre-refactor, avatars were served by gravatar.com so the backend whitelist was never hit.
Observed in production (trawl.me)
:size="24"→ request for-48.png→ 422:size="200"→ request for-400.png→ 422Every downstream project (trawl, comes, montaine, pierreb) is affected because they all consume the Devkit Vue component.
Fix
Add a computed
avatarSizethat snaps the requested size (this.size * 2) to the smallest allowed sharp size>=requested, capped at 1024:The
SHARP_SIZESconstant carries a JSDoc pointing at the backend whitelist file so future updates stay in sync.Tests
Added 5 unit tests covering the resolution matrix:
Verify
Summary by CodeRabbit
Bug Fixes
Tests